package com.app.service.Impl;

import com.app.mapper.AreaMapper;
import com.app.model.AreaModel;
import com.app.service.AreaService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class AreaServiceImpl implements AreaService {
    @Autowired
    private AreaMapper areaMapper;

    @Override
    public List<AreaModel> selectTree() {
        return areaMapper.selectList(null);
    }

    @Override
    public AreaModel selectById(Integer integer) {
        return areaMapper.selectById(integer);
    }

    @Override
    public List<AreaModel> selectTown() {
        QueryWrapper<AreaModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pid", 0);
        return areaMapper.selectList(queryWrapper);
    }

    @Override
    public List<AreaModel> selectVillage(Integer id) {
        QueryWrapper<AreaModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pid", id);
        return areaMapper.selectList(queryWrapper);
    }
}
